<table width="100%"><tr><td width="20%">
<a href="../index.html">&lt; index</a><br />
<a href="index.html">&lt; 15. Heightmap toolkit</a><br />
<a href="heightmap_init.html">&lt; 15.1 Creating a heightmap</a>
</td><td width="60%">
<p align="center">
=====================================<br />
15.2 Basic operations<br />
=====================================<br />
</p></td><td width="20%">
<a href="heightmap_modify.html">&gt; 15.3 Modifying the heightmap</a>
</td></tr></table>
<style type="text/css">
.code { color:#444444; background-color:#EEEEEE;}
pre { color:#444444; background-color:#EEEEEE;}
table.param td { border : 1px solid #000000; }
th { background-color: #44BBFF; color: #FFFFFF }
table.none td { border : 0 }
</style>
<br />
Those are simple operations applied either on a single map cell or on every map cell.
<br />
<a href="#15.2.1">15.2.1 Setting a cell value<br /></a>
<a href="#15.2.2">15.2.2 Adding a float value to all cells<br /></a>
<a href="#15.2.3">15.2.3 Multiplying all values by a float<br /></a>
<a href="#15.2.4">15.2.4 Resetting all values to 0.0<br /></a>
<a href="#15.2.5">15.2.5 Clamping all values<br /></a>
<a href="#15.2.6">15.2.6 Copying values from another heightmap<br /></a>
<a href="#15.2.7">15.2.7 Normalizing values<br /></a>
<a href="#15.2.8">15.2.8 Doing a lerp operation between two heightmaps<br /></a>
<a href="#15.2.9">15.2.9 Adding two heightmaps<br /></a>
<a href="#15.2.10">15.2.10 Multiplying two heightmaps<br /></a>
<br />
<a name="15.2.1"></a><h4>15.2.1 Setting a cell value</h4>
Once the heightmap has been created, you can do some basic operations on the values inside it.<br />
You can set a single value :<br />
<p class="code"><pre>
C++ : void TCODHeightmap::setValue(int x, int y, float v)
C   : void TCOD_heightmap_set_value(TCOD_heightmap_t *hm, int x, int y, float value)
Py  : heightmap_set_value(hm, x, y, value)
</pre></p>
<table class="param">
<tr><th>Parameter</th><th>Description</th></tr>
<tr><td>hm</td><td>In the C version, the address of the heightmap struct returned by the <a href="heightmap_init.html">creation function</a>.</td></tr>
<tr><td>x,y</td><td>Coordinates of the cells to modify inside the map.<br />0 &lt;= x &lt; map width<br />0 &lt;= y &lt; map height</td></tr>
<tr><td>value</td><td>The new value of the map cell.</td></tr>
</table>
<hr />
<a name="15.2.2"></a><h4>15.2.2 Adding a float value to all cells</h4>
<p class="code"><pre>
C++ : void TCODHeightmap::add(float value)
C   : void TCOD_heightmap_add(TCOD_heightmap_t *hm, float value)
Py  : heightmap_add(hm, value)
</pre></p>
<table class="param">
<tr><th>Parameter</th><th>Description</th></tr>
<tr><td>hm</td><td>In the C version, the address of the heightmap struct returned by the <a href="heightmap_init.html">creation function</a>.</td></tr>
<tr><td>value</td><td>Value to add to every cell.</td></tr>
</table>
<hr />
<a name="15.2.3"></a><h4>15.2.3 Multiplying all values by a float</h4>
<p class="code"><pre>
C++ : void TCODHeightmap::scale(float value)
C   : void TCOD_heightmap_scale(TCOD_heightmap_t *hm, float value)
Py  : heightmap_scale(hm, value)
</pre></p>
<table class="param">
<tr><th>Parameter</th><th>Description</th></tr>
<tr><td>hm</td><td>In the C version, the address of the heightmap struct returned by the <a href="heightmap_init.html">creation function</a>.</td></tr>
<tr><td>value</td><td>Every cell's value is multiplied by this value.</td></tr>
</table>
<hr />
<a name="15.2.4"></a><h4>15.2.4 Resetting all values to 0.0</h4>
<p class="code"><pre>
C++ : void TCODHeightmap::clear()
C   : void TCOD_heightmap_clear(TCOD_heightmap_t *hm)
Py  : heightmap_clear(hm)
</pre></p>
<table class="param">
<tr><th>Parameter</th><th>Description</th></tr>
<tr><td>hm</td><td>In the C version, the address of the heightmap struct returned by the <a href="heightmap_init.html">creation function</a>.</td></tr>
</table>
<hr />
<a name="15.2.5"></a><h4>15.2.5 Clamping all values</h4>
<p class="code"><pre>
C++ : void TCODHeightmap::clamp(float min, float max)
C   : void TCOD_heightmap_clamp(TCOD_heightmap_t *hm, float min, float max)
Py  : heightmap_clamp(hm, mi, ma)
</pre></p>
<table class="param">
<tr><th>Parameter</th><th>Description</th></tr>
<tr><td>hm</td><td>In the C version, the address of the heightmap struct returned by the <a href="heightmap_init.html">creation function</a>.</td></tr>
<tr><td>min,max</td><td>Every cell value is clamped between min and max.<br />min &lt; max</td></tr></table>
<hr />
<a name="15.2.6"></a><h4>15.2.6 Copying values from another heightmap</h4>
<p class="code"><pre>
C++ : void TCODHeightmap::copy(const TCODHeightMap *source)
C   : void TCOD_heightmap_copy(const TCOD_heightmap_t *source,TCOD_heightmap_t *dest)
Py  : heightmap_copy(source,dest)
</pre></p>
<table class="param">
<tr><th>Parameter</th><th>Description</th></tr>
<tr><td>source</td><td>Each cell value from the source heightmap is copied in the destination (this for C++) heightmap.<br />The source and destination heightmap must have the same width and height.</td></tr>
<tr><td>hm</td><td>In the C version, the address of the destination heightmap.</td></tr>
</table>
<hr />
<a name="15.2.7"></a><h4>15.2.7 Normalizing values</h4>
<p class="code"><pre>
C++ : void TCODHeightmap::normalize(float min=0.0f, float max=1.0f)
C   : void TCOD_heightmap_normalize(TCOD_heightmap_t *hm, float min, float max)
Py  : heightmap_normalize(hm, mi=0.0, ma=1.0)
</pre></p>
<table class="param">
<tr><th>Parameter</th><th>Description</th></tr>
<tr><td>hm</td><td>In the C version, the address of the heightmap struct returned by the <a href="heightmap_init.html">creation function</a>.</td></tr>
<tr><td>min,max</td><td>The whole heightmap is translated and scaled so that the lowest cell value becomes min and the highest cell value becomes max<br />min &lt; max</td></tr></table>
<hr />
<a name="15.2.8"></a><h4>15.2.8 Doing a lerp operation between two heightmaps</h4>
<p class="code"><pre>
C++ : void TCODHeightmap::lerp(const TCODHeightMap *a, const TCODHeightMap *b,float coef)
C   : void TCOD_heightmap_lerp_hm(const TCOD_heightmap_t *a, const TCOD_heightmap_t *b, TCOD_heightmap_t *res, float coef)
Py  : heightmap_lerp_hm(a, b, res, coef)
</pre></p>
<table class="param">
<tr><th>Parameter</th><th>Description</th></tr>
<tr><td>a</td><td>First heightmap in the lerp operation.</td></tr>
<tr><td>b</td><td>Second heightmap in the lerp operation.</td></tr>
<tr><td>coef</td><td>lerp coefficient.<br />For each cell in the destination map (this for C++), value = a.value + (b.value - a.value) * coef</td></tr>
<tr><td>res</td><td>In the C version, the address of the destination heightmap.</td></tr>
</table>
<hr />
<a name="15.2.9"></a><h4>15.2.9 Adding two heightmaps</h4>
<p class="code"><pre>
C++ : void TCODHeightmap::add(const TCODHeightMap *a, const TCODHeightMap *b)
C   : void TCOD_heightmap_add_hm(const TCOD_heightmap_t *a, const TCOD_heightmap_t *b, TCOD_heightmap_t *res)
Py  : heightmap_add_hm(a, b, res)
</pre></p>
<table class="param">
<tr><th>Parameter</th><th>Description</th></tr>
<tr><td>a</td><td>First heightmap.</td></tr>
<tr><td>b</td><td>Second heightmap. For each cell in the destination map (this for C++), value = a.value + b.value</td></tr>
<tr><td>res</td><td>In the C version, the address of the destination heightmap.</td></tr>
</table>
<hr />
<a name="15.2.10"></a><h4>15.2.10 Multiplying two heightmaps</h4>
<p class="code"><pre>
C++ : void TCODHeightmap::multiply(const TCODHeightMap *a, const TCODHeightMap *b)
C   : void TCOD_heightmap_multiply_hm(const TCOD_heightmap_t *a, const TCOD_heightmap_t *b, TCOD_heightmap_t *res)
Py  : heightmap_multiply_hm(a, b, res)
</pre></p>
<table class="param">
<tr><th>Parameter</th><th>Description</th></tr>
<tr><td>a</td><td>First heightmap.</td></tr>
<tr><td>b</td><td>Second heightmap. For each cell in the destination map (this for C++), value = a.value * b.value</td></tr>
<tr><td>res</td><td>In the C version, the address of the destination heightmap.</td></tr>
</table>
<hr />

